package com.zf.bm.common.core.sys.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zf.bm.common.core.sys.entity.Role;
import com.zf.bm.common.core.sys.service.ISignInterface;
import com.zf.bm.common.core.sys.service.RoleService;
import com.zf.bm.common.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * <p>
 * 角色签名实现类
 * </p>
 *
 * @author guojing
 * @since 2023-07-06
 */
@Component("role")
@Slf4j
public class RoleSignServiceImpl implements ISignInterface {
    @Resource
    private RoleService roleService;

    @Override
    public ImmutablePair<String, String> getSignData(Integer id) {
        Role role = roleService.selectNameAndSm3ById(id);
        log.info("getSignData role: " + role);
        if (ObjectUtils.isEmpty(role)) {
            return null;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", role.getName());
        return ImmutablePair.of(JsonUtils.objectToString(jsonObject), role.getSm3());
    }
}
